package com.example.adminjiemian;

import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView etMain;

    String prefName="com.example.adminjiemian";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        saveDataWithSharedPreferences();

        etMain = (TextView) findViewById(R.id.et_main);

        Intent intent1=getIntent();
        String username = intent1.getStringExtra("username");

        if(username!=null){
          UserInfo userInfo=new UserInfo(intent1.getStringExtra("username"),
                  intent1.getStringExtra("password"),
                  intent1.getIntExtra("age",0),
                  intent1.getBooleanExtra("gender",false));

         etMain.setText("用户名 :"+userInfo.username+
                 "\r\n密码 :"+userInfo.password+
                 "\n年龄 :"+userInfo.age+
                 "\n性别 :"+(userInfo.gender?"男":"女"));
      }else {

          Intent intent=new Intent(this,Login.class);
          startActivity(intent);
          finish();
      }

    }

//private UserInfo getUserInfo(){
//        return UserInfo;
//}
public void saveDataWithSharedPreferences(){
    SharedPreferences sharedPreferences=getSharedPreferences(prefName,MODE_PRIVATE);
    SharedPreferences.Editor edit=sharedPreferences.edit();
    edit.putBoolean("bool",false);
    edit.putFloat("float",(float)3.13);
    edit.putInt("int",123);
    edit.putString("username","luojie");
    edit.putString("password","123456");
    edit.apply();
    String username = sharedPreferences.getString("username", "");
    String password = sharedPreferences.getString("password", "");


}

}
